﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using APPLICATION.Dict.Contracts;
using APPLICATION.Dict.EBK;
using DevExpress.XtraTabbedMdi;

namespace APPLICATION
{
    public partial class MainForm : Form
    {
        private int childFormNumber = 0;

        public MainForm()
        {
            InitializeComponent();
        }

        private void ShowNewForm(object sender, EventArgs e)
        {
            Form childForm = new Form();
            childForm.MdiParent = this;
            childForm.Text = "Window " + childFormNumber++;
            childForm.Show();

        }

        private void OpenFile(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            openFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
            if (openFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = openFileDialog.FileName;
            }
        }

        private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            saveFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
            if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FileName = saveFileDialog.FileName;
            }
        }

        private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void CutToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
        }

        private void ToolBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
           // toolStrip.Visible = toolBarToolStripMenuItem.Checked;
        }

        private void StatusBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
        }

        private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }

        private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }

        private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }

        private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.ArrangeIcons);
        }

        private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form childForm in MdiChildren)
            {
                childForm.Close();
            }
        }

        private void uSerManagerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            if (childFormNumber == 0)
            {
                /*
                modules.UMAN userManegerForm = new APPLICATION.modules.UMAN();
                userManegerForm.MdiParent = this;
                userManegerForm.Text = "User Manager " + childFormNumber++;
                userManegerForm.Show();
                userManegerForm.Dock = DockStyle.Fill;
                */

            }
            else
            {

                MessageBox.Show("Opened  Windows Please  close  it  first");
            }
        }

        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            //MessageBox.Show("Are  You  Sure ?", "Closing APP", MessageBoxButtons.OKCancel);
            
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            Login LoginWindow = new Login();
            LoginWindow.ShowDialog();

            if (LoginWindow.DialogResult == DialogResult.OK)
            {

                MainFrame frm = new MainFrame();
                frm.MdiParent = this;
                frm.Show();

            }
            else
            {

                Close();
            }
        }

        private void городаToolStripMenuItem_Click(object sender, EventArgs e)
        {
            /*
            Dict.City.FrmCity Cities =  new Dict.City.FrmCity();
            Cities.MdiParent = this;
            Cities.Show();
            //by Andro            
            //Cities.Dock = DockStyle.Fill;
            */

                  
        }

        private void справочникКлиентовToolStripMenuItem_Click(object sender, EventArgs e)
        {
            /*
            Contracts clients = new Contracts();
            clients.MdiParent = this;
            clients.Show();
            clients.Dock = DockStyle.Fill;
             */
        }

        private void контрактыToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Dict.Contracts.frmContracts frmCont = new frmContracts();
            frmCont.MdiParent = this;
            frmCont.Show();
      
        }

        public class StrippedTabbedMdi : XtraTabbedMdiManager
        {
            public StrippedTabbedMdi() : base() { }
            public StrippedTabbedMdi(IContainer c) : base(c) { }
            protected override void PatchActiveChild()
            {
            }
            protected override void PatchBeforeActiveChild(Form activatedForm)
            {

            }
            protected override void RegisterMDIChild(Form child)
            {
                if (child == null)
                    return;
                XtraMdiTabPage newPage = CreateNewPage(child);
                Pages.Add(newPage);
                OnPageAdded(new MdiTabPageEventArgs(newPage));
            }
        }

        private void должностиToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Dict.Post.FrmPost Posts = new Dict.Post.FrmPost();
            Posts.MdiParent = this;
            Posts.Show();
        }

        private void mnuDepartments_Click(object sender, EventArgs e)
        {
            APPLICATION.Departments.Form1 frmDep = new Departments.Form1();
            frmDep.MdiParent = this;
            frmDep.Show();
        }

        private void mnuClose_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.ActiveMdiChild.Name!="MainFrame") { this.ActiveMdiChild.Close(); }
                
            }

            catch (Exception e1)
            {
                
            }
        }

        private void mnuEBK_Click(object sender, EventArgs e)
        {
            Dict.EBK.frmEBK frm=new frmEBK();
            frm.MdiParent = this;
            frm.Show();
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }
    }
}
